//
//  AXFMyOrderCell.m
//  AIXF
//
//  Created by zhanghui on 2017/7/14.
//  Copyright © 2017年 Macx. All rights reserved.
//

#import "AXFMyOrderCell.h"
#import "AXFOrderStatusModel.h"
#import <UIImageView+WebCache.h>
@interface AXFMyOrderCell ()

@property (weak, nonatomic) IBOutlet UILabel *createTimeLabel;

@property (weak, nonatomic) IBOutlet UILabel *statusLabel;
@property (weak, nonatomic) IBOutlet UIImageView *productImageView1;

@property (weak, nonatomic) IBOutlet UIImageView *productImageView2;
@property (weak, nonatomic) IBOutlet UIImageView *productImageView3;

@property (weak, nonatomic) IBOutlet UIImageView *productImageView4;

@property (weak, nonatomic) IBOutlet UIImageView *productImageView5;

@property (weak, nonatomic) IBOutlet UILabel *productCountLabel;

@property (weak, nonatomic) IBOutlet UILabel *priceLabel;
@property (weak, nonatomic) IBOutlet UIStackView *stackView;

@property(nonatomic,strong)NSMutableArray *URLS;



@end

@implementation AXFMyOrderCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.selectionStyle = UITableViewCellSelectionStyleNone;

}


- (void)setOrderModel:(AXFMyOrederModel *)orderModel{
    
    _orderModel = orderModel;
    
    //创建时间
    self.createTimeLabel.text = orderModel.create_time;
    
    //订单状态
    self.statusLabel.text = [orderModel.status_timeline[0] status_title];
    
    //图片赋值
    
    
    //商品数量label
    self.productCountLabel.text  = [NSString stringWithFormat:@"共%zd件商品",
                                    orderModel.order_goods.count];
    
    //金额
    self.priceLabel.text = [NSString stringWithFormat:@"实付:$%@", orderModel.real_amount];

    
    //设置图片,判断商品的数量
    if (orderModel.order_goods.count > 4) {
        
        //最多只有5个,取前4个，在模型中
        
        for (NSInteger i = 0; i < 4; i++)  {
            
            NSArray *arr = orderModel.order_goods[i];
            
            //创建模型
            AXFOrderGoodsModel *good = arr[0];
            
            NSURL *url = [NSURL URLWithString:good.img];
            
              [(UIImageView *)self.stackView.arrangedSubviews[i] sd_setImageWithURL:url];
        
        }
        
        //隐藏第四个，第五个
         self.productImageView5.hidden = NO;
        
    }else{

        //小于4个,就是
    
        for (NSInteger i = 0; i < orderModel.order_goods.count; i++)  {
            
            NSArray *arr = orderModel.order_goods[i];
            
            //创建模型
            AXFOrderGoodsModel *good = arr[0];
            
            NSURL *url = [NSURL URLWithString:good.img];
            
            [(UIImageView *)self.stackView.arrangedSubviews[i] sd_setImageWithURL:url];
            
        }
        
        self.productImageView5.hidden = YES;
        
        
    }
    

    
    
}

- (NSMutableArray *)URLS{
    
    if (!_URLS) {
        
        NSMutableArray *arrM = [NSMutableArray array];
        //获取到所有的URL
        for (NSArray *arr in self.orderModel.order_goods) {
            
            //创建模型
            AXFOrderGoodsModel *model = arr[0];
            
            NSURL *url = [NSURL URLWithString:model.img];
            
            [arrM addObject:url];
            
        }
        
        _URLS = arrM;
        
    }
    
    return _URLS;
}




@end
